#include "SimpleGrid.h"

#include <cstring>
using std::memset;

#include "../../../base.h"
#include "../../../qt/Logger.h"

/*
	SimpleGrid
*/

/*	public	*/

SimpleGrid::SimpleGrid(int width, int height) :
	_width(width),
	_height(height) {

	/* data */
	_data = new int[width * height];

	/* initialise */
	memset(_data, 0, width * height * sizeof(int));
}

SimpleGrid::SimpleGrid(Grid const& grid) :
	_width(grid.getWidth()),
	_height(grid.getHeight()) {

	/* data */
	_data = new int[_width * _height];

	/* copy */
	for(int i = 0; i != _width; ++i) {
		for(int j = 0; j != _height; ++j) {
			_data[doGetIndex(i, j)] = grid.getTile(i, j);
		}
	}
}

SimpleGrid::~SimpleGrid() {
	delete[] _data;
}

void SimpleGrid::setTile(int x, int y, int value) {
//	Logger::debug(QString("=== SimpleGrid::setTile(x = %1, y = %2, value = %3)").arg(x).arg(y).arg(value));
	_data[doGetIndex(x, y)] = value;
}

int SimpleGrid::getWidth() const {
	return _width;
}
int SimpleGrid::getHeight() const {
	return _height;
}

